<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>包邮设置管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			yzAddr();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				rules:{          
					receiveAreaId:{required:true,addr:true}, 
	            },
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			jQuery.validator.addMethod("addr", function(value,  
	                element, param) { 
				   var stg=$("#stgs").val();
				   if(stg==1){
					   return false;
				   }else{
					   return true;
				   }
				    
	        }, $.validator.format("同一发货区域，收货区域 的邮费只能设置一个 "));
		});
		function yzAddr(){
			var sendAreaId=$("#sendAreaId").val();
			var receiveAreaId=$("#receiveAreaId").val();
			var id=$("#ids").val();
			 $.ajax({
			    	type:"post",
			    	data:{"sendAreaId":sendAreaId,"id":id,"receiveAreaId":receiveAreaId},
			    	dataType:"json",
			    	url:"${ctx}/sys/freeWaybill/yzAddress",
			    	success:function(e){
			    		if(e.st==1){
			    			$("#stgs").val(1)
			    		}else{
			    			$("#stgs").val(0)
			    		}
			    	}
			    })
		}
	</script>
</head>
<body>
    <input name="stgs" id="stgs" type="hidden"/>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/freeWaybill/">包邮设置列表</a></li>
		<li class="active"><a href="${ctx}/sys/freeWaybill/form?id=${freeWaybill.id}">包邮设置<shiro:hasPermission name="sys:freeWaybill:edit">${not empty freeWaybill.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:freeWaybill:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="freeWaybill" action="${ctx}/sys/freeWaybill/save" method="post" class="form-horizontal">
		 <form:hidden path="id" id="ids"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">发货区域：</label>
			<div class="controls">
				<form:select id="sendAreaId" path="sendAreaId" class="input-medium required" onclick="yzAddr()">
				<form:option value="" label="发货区域"/>
			    <form:options items="${area}" htmlEscape="false" itemValue="id" itemLabel="name"/></form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">收货区域：</label>
			<div class="controls">
				<form:select id="receiveAreaId" path="receiveAreaId" class="input-medium required" onchange="yzAddr()">
				<form:option value="" label="收货区域"/>
			    <form:options items="${areas}" htmlEscape="false" itemValue="id" itemLabel="name"/></form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">包邮金额：</label>
			<div class="controls">
				<form:input path="money" htmlEscape="false" class="input-xlarge digits required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="sys:freeWaybill:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>